<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Upload;

class FileController extends Controller {
	/**
	 * @上传游戏文件控制器
	 * @author zheng.wang <40085262@qq.com> 
	*/
	public function uploadFile()
	{
		$upload = new \Think\Upload();// 实例化上传类
		$upload->maxSize   =     0 ;// 设置附件上传大小
		$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg', 'doc', 'docx');// 设置附件上传类型
		$upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
		$upload->savePath  =      '/contract/'; // 设置附件上传目录
		$upload->saveName  =     ''; //上传文件命名规则，[0]-函数名，[1]-参数，多个参数使用数组
		$upload->autoSub   =     false;
		$info   =   $upload->uploadOne( $_FILES['upload']);
		if(!$info) {// 上传错误提示错误信息
		    $data['status'] = 0;
            $data['info']   = $upload->getError();
		}else{// 上传成功 获取上传文件信息
			$data['status'] = 1;
		    $data['url']   =  $info['savename'];
			}
		$this->ajaxReturn($data);	
    }
	
	public function downloadFile(){
		$map['recharge_log_id'] = I('request.recharge_log_id');
		$info = M('recharge_log')->where($map)->find();
		$file = 'http://'.$_SERVER['HTTP_HOST'].$info['img_url'];
		 // echo __ROOT__ ;
		 // die;
		header("Content-type: image/jpeg");
		header("Content-Disposition: attachment; filename={$filename}");
		header("Content-length: " . filesize($file));
		readfile($file);
	}
	
}